home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Apr 89 / T0029-Re[2] Segmentation -Apr89 < prev    next >
Encoding:
Text File  |  1989-04-19  |  2.3 KB  |  51 lines  |  [TEXT/GEOL]

  1. Item    9680192                         19-April-89        10:21
  2.  
  3. From:   BIANCHI1                        Bianchi, Curt
  4.  
  5. To:     ROLLIN1                         Rollin, Keith A.
  6.         D2215                           Dac SW, Wilma Blair, PRT
  7.  
  8. cc:     MACAPP.TECH$                    MACAPP Tech
  9.  
  10. Sub:    Re- Re- Segmentation changes?
  11.  
  12. Keith, (and Les),
  13.  
  14. I think what Les is getting at is that if you know a procedure call will not
  15. affect the heap, then you can pass a field of an object safely, knowing the
  16. object will not move.  In the case of TStaticText.SetText, it's in a
  17. non-resident segment.  Thus a segment load is possible, which may shuffle the
  18. heap and invalidate the address of an object field passed to SetText.  So you
  19. have to copy the string from the object to a local variable and pass the local
  20. variable to SetText.
  21.  
  22. Note that there are some very subtle issues here (and somebody correct me if I
  23. get this wrong).  The string passed to SetText is passed by value.  Since it's
  24. a data structure longer than four bytes, the Pascal compiler actually passes
  25. the address of the string to SetText.  The compiler generates code IN SetText
  26. to copy the string onto the stack.  This means that if calling SetText causes a
  27. segment load and you pass a field of an object as the string, the address of
  28. the string could become invalid BEFORE SetText has a chance to copy it.  So
  29. putting SetText in a resident segment would allow you to safely pass a string
  30. in an object.
  31.  
  32. Suppose the string in SetText was a VAR parameter.  In that case putting
  33. SetText in a resident segment wouldn't help.  If you look at the code in
  34. SetText you will find that it performs operations that affect the heap.  For
  35. example, it calls the Toolbox routine NewString which allocates a new handle,
  36. obviously affecting the heap.  It also calls other methods which may themselves
  37. affect the heap or cause segment loads.
  38.  
  39. Since these issues are tricky you are better off erring on the safe side when
  40. you're not sure.  Errors caused by these mistakes are often difficult to track
  41. down and may not show up until you run your program in low memory situations or
  42. with heap scrambling.
  43.  
  44. In response to Les's original question, could SetText be put in a resident
  45. segment, I believe things are already frozen for the next APDA release.
  46. Perhaps it can be done for future release.
  47.  
  48. Curt Bianchi
  49. Apple Computer
  50.  
  51.